@echo off
echo Spring IoC和AOP演示项目
echo ================================

REM 检查Java是否安装
java -version >nul 2>&1
if errorlevel 1 (
    echo 错误: 未找到Java，请确保已安装Java 8或更高版本
    pause
    exit /b 1
)

REM 检查lib目录是否存在
if not exist "lib" (
    echo 错误: 未找到lib目录，请先运行download-dependencies.bat下载依赖
    pause
    exit /b 1
)

echo 正在编译项目...

REM 创建目标目录
if not exist "target\classes" mkdir target\classes

REM 设置classpath
set CLASSPATH=target\classes
for %%f in (lib\*.jar) do set CLASSPATH=!CLASSPATH!;%%f

REM 编译Java文件
javac -cp "%CLASSPATH%" -d target/classes src/main/java/com/example/annotation/*.java
if errorlevel 1 (
    echo 编译annotation包失败
    pause
    exit /b 1
)

javac -cp "%CLASSPATH%" -d target/classes src/main/java/com/example/aspect/*.java
if errorlevel 1 (
    echo 编译aspect包失败
    pause
    exit /b 1
)

javac -cp "%CLASSPATH%" -d target/classes src/main/java/com/example/config/*.java
if errorlevel 1 (
    echo 编译config包失败
    pause
    exit /b 1
)

javac -cp "%CLASSPATH%" -d target/classes src/main/java/com/example/service/*.java
if errorlevel 1 (
    echo 编译service包失败
    pause
    exit /b 1
)

javac -cp "%CLASSPATH%" -d target/classes src/main/java/com/example/Application.java
if errorlevel 1 (
    echo 编译Application失败
    pause
    exit /b 1
)

echo 编译成功！
echo.
echo 正在运行项目...
echo.

REM 复制资源文件
if not exist "target\classes" mkdir target\classes
copy src\main\resources\*.* target\classes\ >nul 2>&1

REM 运行程序
java -cp "%CLASSPATH%" com.example.Application

echo.
echo 程序执行完成！
pause
